package com.xp.ai.embedding;

import dev.langchain4j.data.embedding.Embedding;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.internal.Utils;
import dev.langchain4j.store.embedding.EmbeddingStore;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.collection.request.CreateCollectionReq;

import java.util.ArrayList;
import java.util.List;


/***
 * 因为我本地没有合适的向量数据库 只有 zilliz 的云数据库，所以这里扩展一个
 */
public class ZillizSassEmbeddingStore implements EmbeddingStore<TextSegment> {

    private String url;
    private String apiKey;

    private String dataBaseName;

    private MilvusClientV2 zillizStoreClient;

    class ZillizStoreClient{

        private MilvusClientV2 milvusClientV2;

        public ZillizStoreClient() {
            milvusClientV2 = new MilvusClientV2(ConnectConfig.builder()
                    .uri(url)
                    .token(apiKey)
                    .secure(false)
                    .connectTimeoutMs(5000L)
                    .build());
        }

        public MilvusClientV2 getMilvusClientV2() {
            return milvusClientV2;
        }
    }


    public ZillizSassEmbeddingStore(String url, String apiKey, String dataBaseName) {
        this.url = url;
        this.apiKey = apiKey;
        this.dataBaseName = dataBaseName;
        this.zillizStoreClient = new ZillizStoreClient().getMilvusClientV2();
    }

    @Override
    public String add(Embedding embedding) {

        return null;
    }

    @Override
    public void add(String id, Embedding embedding) {

    }

    @Override
    public String add(Embedding embedding, TextSegment textSegment) {
        return null;
    }

    @Override
    public List<String> addAll(List<Embedding> embeddings) {
        return null;
    }

    @Override
    public void addAll(List<String> ids, List<Embedding> embeddings, List<TextSegment> embedded) {
        if (!Utils.isNullOrEmpty(ids) && !Utils.isNullOrEmpty(ids) && !Utils.isNullOrEmpty(embeddings)) {
            List<CreateCollectionReq.FieldSchema>  fieldSchemas = new ArrayList<>();

        }
    }
}
